package ggze.GGZEServer.home.service.impl;

import ggze.GGZEServer.home.dao.inter.SoBlanceDao;
import ggze.GGZEServer.home.dao.inter.SoConsumeRecordDao;
import ggze.GGZEServer.home.entity.SoBlance;
import ggze.GGZEServer.home.entity.SoBlanceRecord;
import ggze.GGZEServer.home.entity.SoConsumeRecord;
import ggze.GGZEServer.home.enums.BlanceEnum;
import ggze.GGZEServer.home.service.ConsumeService;
import ggze.actuator.ActuatorController;
import ggze.tool.TimeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ConsumeServiceImpl implements ConsumeService {
    @Autowired
    private ActuatorController actuatorController;
    @Autowired
    private SoBlanceDao soBlanceDao;
    @Autowired
    private SoConsumeRecordDao soConsumeRecordDao;
    @Override
    public boolean changeConsume(SoBlance soBlance, String type) throws Exception {
        SoBlance soUser = soBlanceDao.isSelect("f_user_id", soBlance.getF_USER_ID());
        if (soBlance.getF_CONSUME_JF() != 0) {
            soUser.setF_CONSUME_JF(soUser.getF_CONSUME_JF() + soBlance.getF_CONSUME_JF());
        }
        actuatorController.execute(soUser, "update", soBlanceDao);
        //流水
        SoConsumeRecord soConsumeRecord = new SoConsumeRecord();
        String time = TimeUtils.getTimeFormat();
        soConsumeRecord.setF_CREATE_TIME(time);
        soConsumeRecord.setF_METHOD_TIME(time);
        soConsumeRecord.setF_NOTE(BlanceEnum.CONSUME.getLables(type));
        soConsumeRecord.setF_SELES1(type);
        soConsumeRecord.setF_USER_NAME(soUser.getF_USER_NAME());
        soConsumeRecord.setF_USRE_ID(soUser.getF_USER_ID());
        soConsumeRecord.setF_MONEY(soBlance.getF_CONSUME_JF());
        actuatorController.execute(soConsumeRecord, "add", soConsumeRecordDao);
        return true;
    }
}
